package com.ssy.lingxi.logistics.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.SelectVO;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.logistics.api.dto.response.CommonSelectResponse;
import com.ssy.lingxi.logistics.model.request.SelectCompanyListRequest;
import com.ssy.lingxi.logistics.model.response.CompanyMemberSelectedResponse;
import com.ssy.lingxi.logistics.model.response.CompanySelectResponse;
import com.ssy.lingxi.logistics.model.response.ReceiverAddressSelectResponse;
import com.ssy.lingxi.logistics.model.response.ShipperAddressSelectResponse;
import com.ssy.lingxi.logistics.service.ISelectService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @menu 能力中心 - 物流能力 - 下拉框
 * @author yzc
 * @version 2.0.0
 * @date 2020/7/10
 */
@RestController
@RequestMapping("/logistics/select")
public class AbilitySelectController extends BaseController {

    @Resource
    private ISelectService selectService;

    // 物流公司============================================

    /**
     * 能力中心 - 物流公司查询全部(不同合作类型)
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping(value = "/listCompany")
    public Wrapper<List<CommonSelectResponse>> listCompany(SelectCompanyListRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return selectService.listCompany(sysUser, request);
    }

    /**
     * 能力中心 - 物流公司下拉查询(平台合作类型)
     * @return 返回结果
     */
    @GetMapping(value = "/listMemberCompany")
    public Wrapper<List<CompanySelectResponse>> listMemberCompany() {
        UserLoginCacheDTO sysUser = getSysUser();
        return selectService.listMemberCompany(sysUser);
    }

    /**
     * 能力中心 - 物流公司下拉查询(平台类型,模糊匹配)
     * @param name 名称
     * @return 返回结果
     */
    @GetMapping(value = "/listMemberCompanyQuery")
    public Wrapper<List<SelectVO>> listMemberCompanyQuery(@RequestParam(value = "name", defaultValue = "") String name) {
        UserLoginCacheDTO sysUser = getSysUser();
        return selectService.listMemberCompanyQuery(sysUser, name);
    }

    /**
     * 能力中心 - 查询已添加的物流服务商
     * @return 返回结果
     */
    @GetMapping(value = "/listMemberCompanySelected")
    public Wrapper<List<CompanyMemberSelectedResponse>> listMemberCompanySelected() {
        UserLoginCacheDTO sysUser = getSysUser();
        return selectService.listMemberCompanySelected(sysUser);
    }

    // 发货地址============================================

    /**
     * 能力中心 - 发货地址查询全部(按照是否默认排序)
     * @return 返回结果
     */
    @GetMapping(value = "/listShipperAddress")
    public Wrapper<List<ShipperAddressSelectResponse>> listShipperAddress() {
        UserLoginCacheDTO sysUser = getSysUser();
        return selectService.listShipperAddress(sysUser.getMemberId(), sysUser.getMemberRoleId());
    }

    /**
     * 能力中心 - 根据会员查询全部发货地址(按照是否默认排序)
     * @return 返回结果
     */
    @GetMapping(value = "/listMemberShipperAddress")
    public Wrapper<List<ShipperAddressSelectResponse>> listMemberShipperAddress(@RequestParam("memberId") Long memberId,
                                                                                @RequestParam("roleId") Long roleId) {
        UserLoginCacheDTO sysUser = getSysUser();
        return selectService.listShipperAddress(memberId, roleId);
    }

    /**
     * 能力中心 - 发货人下拉查询
     * @param name 名称
     * @return 返回结果
     */
    @GetMapping(value = "/listShipperSelect")
    public Wrapper<List<SelectVO>> listShipperSelect(@RequestParam(value = "name", defaultValue = "") String name) {
        UserLoginCacheDTO sysUser = getSysUser();
        return selectService.listShipperSelect(sysUser, name);
    }

    // 收货地址============================================

    /**
     * 能力中心 - 收货地址查询全部(按照是否默认排序)
     * @return 返回结果
     */
    @GetMapping(value = "/listReceiverAddress")
    public Wrapper<List<ReceiverAddressSelectResponse>> listReceiverAddress() {
        UserLoginCacheDTO sysUser = getSysUser();
        return selectService.listReceiverAddress(sysUser.getMemberId(), sysUser.getMemberRoleId());
    }

    /**
     * 能力中心 - 根据会员查询全部收货地址(按照是否默认排序)
     * @return 返回结果
     */
    @GetMapping(value = "/listMemberReceiverAddress")
    public Wrapper<List<ReceiverAddressSelectResponse>> listMemberReceiverAddress(@RequestParam("memberId") Long memberId,
                                                                                  @RequestParam("roleId") Long roleId
    ) {
        UserLoginCacheDTO sysUser = getSysUser();
        return selectService.listReceiverAddress(memberId, roleId);
    }

    // 运费地址============================================

    /**
     * 能力中心 - 运费模板下拉框
     * @return 返回结果
     */
    @GetMapping(value = "/listFreightTemplate")
    public Wrapper<List<CommonSelectResponse>> listFreightTemplate() {
        UserLoginCacheDTO sysUser = getSysUser();
        return selectService.listFreightTemplate(sysUser);
    }
}
